/*******************************************************************************
 * Copyright (c) 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Bartosz Michalik (bartosz.michalik@gmail.com)
 *******************************************************************************/
package org.eclipse.pde.internal.ui.editor.product.customization;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.pde.core.plugin.*;
import org.eclipse.pde.internal.core.iproduct.ICustomizationInfo;
import org.eclipse.pde.internal.core.iproduct.IProductTransform;

/**
 * @author Bartosz Michalik
 *
 */
public class RestoreTransformAction extends TransformationAction {

	/**
	 * @param info
	 * @param selection
	 */
	public RestoreTransformAction(ICustomizationInfo info, IStructuredSelection selection) {
		super("Restore to configuration", info, selection);
		Object element = selection.getFirstElement();
		if (element instanceof IPluginElement || element instanceof IPluginExtension) {
			setEnabled(info.getTransformsManager().isTransformed((IPluginObject) element));
		} else
			setEnabled(false);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.pde.internal.ui.editor.product.customization.TransformationAction#run()
	 */
	public void run() {
		Object selected = fSelection.getFirstElement();
		if (selected instanceof IPluginObject)
			fInfo.getTransformsManager().remove((IPluginObject) selected);
		else if (selected instanceof IProductTransform) {
			fInfo.getTransformsManager().remove((IProductTransform) selected);
		}
	}

}
